#include <bits/stdc++.h>
#define VNAME(name) (#name)
#define debug(x) {auto debugx = x; std::cout << " (" << VNAME(x) << ": " << debugx << ") ";}
#define debugendl(x) {auto debugx = x; std::cout << " (" << VNAME(x) << ": " << debugx << ") " << std::endl;}
#define F_(n) cout << fixed << setprecision(n)
#define gc() (ibo_ == ied_ ? (ied_ = buf + fread(ibo_ = buf, 1, 1 << 20, stdin), ibo_ == ied_ ? EOF : *ibo_++) : *ibo_++)
#define read() ({ int x = 0, f = 1; char c = gc(); while(c < '0' || c > '9') { if (c == '-') f = -1; c = gc();} while(c >= '0' && c <= '9') x = x * 10 + (c & 15), c = gc(); f * x; })
char buf[1 << 20], puf[1 << 20], *_p_ = puf, *ibo_, *ied_;
#define pr(x) (_p_ - puf == 1 << 20 ? (fwrite(puf, 1, 1 << 20, stdout), _p_ = puf) : 0, *_p_++ = x)
int print(long long x) { return x <= 9 ? pr(x + '0') : (print(x / 10), pr(x % 10 + '0')); }
#ifndef ONLINE_JUDGE
#else
	#define endl '\n'
#endif
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());
bool _OJ_Flag = true;
int arr[N];
static int ____________________________________________________ = []() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    return 0;
}();//*/
int solve(int n, int m) {
    int maxn = 0, C = arr[1] + m, q = 1;
    for (int i = 1; i <= n; ++ i) {
        while (arr[i + 1] <= C) i ++;
        maxn = max(maxn, (i > n ? n : i) - q + 1);// debugendl(i);
        if (i > n) break;
        C = arr[i + 1] - m;
        while (arr[q] < C) q ++;
        C = arr[q] + m;
    }
    return maxn;
}
signed main() {
    #ifndef ONLINE_JUDGE
		_OJ_Flag = false; //freopen("C:\\Users\\lenovo\\Desktop\\in.in", "r", stdin);
	#endif
    int t = 1;
    //cin >> t;
    while (t --) {
        int n, m;
        cin >> n >> m;
        for (int i = 1; i <= n; ++ i) cin >> arr[i];
        sort(arr + 1, arr + n + 1);
        cout << solve(n, m);
        //debug(solve(n));
    }
    #ifndef ONLINE_JUDGE
        cout << endl;
		system("pause");
	#endif
    return 0;
}